package de.uni_mannheim.informatik.ai.dame_ai.util;

import java.awt.*;

@SuppressWarnings("serial")
class BitmapComponent extends Canvas {
	private Image img;
	MediaTracker mt;

	public BitmapComponent(String fname) {
		img = getToolkit().getImage(fname);
		mt = new MediaTracker(this);

		mt.addImage(img, 0);
		try {
			mt.waitForAll();
		} catch (InterruptedException e) {
			// nothing
		}
	}

	public void paint(Graphics g) {
		g.drawImage(img, 0, 0, this);
	}

	public Dimension getPreferredSize() {
		return new Dimension(img.getWidth(this), img.getHeight(this));
	}

	public Dimension getMinimumSize() {
		return new Dimension(img.getWidth(this), img.getHeight(this));
	}

	public void changeImage(String fname) {
		img = getToolkit().getImage(fname);
		mt.addImage(img, 0);
		try {
			mt.waitForAll();
		} catch (InterruptedException e) {
			// nothing
		}
		this.repaint();
	}
}